package letsjava.pattern.mediator;

public class ConcreteMediator implements Mediator {
	// 假设当前有两个成员.
	public ConcreteColleague1 colleague1;
	public ConcreteColleague2 colleague2;
	
	public static void main(String[] args){
		ConcreteColleague1 colleague1 = new ConcreteColleague1();
		ConcreteColleague2 colleague2 = new ConcreteColleague2();
		ConcreteMediator mediator = new ConcreteMediator();
		mediator.colleague1 = colleague1;
		mediator.colleague2 = colleague2;
		colleague1.setMediator(mediator);
		colleague2.setMediator(mediator);
		
		colleague1.sayHello("from colleague1");
		colleague2.sayHello("from colleague2");
		
		
	}

	@Override
    public void sayHello(String a,String b) {
	    // TODO Auto-generated method stub
	    if("1".equals(a)){
	    	colleague1.receiveHello(b);
	    }else if("2".equals(a)){
	    	colleague2.receiveHello(b);
	    }
    }

}